package mblog.core.persist.dao.impl;

import mblog.core.persist.dao.GoodsKeywordDao;
import mblog.core.persist.entity.GoodsKeywordPO;
import mblog.core.persist.entity.PostKeywordPO;
import mtons.modules.annotation.Repository;
import mtons.modules.persist.impl.BaseRepositoryImpl;
import org.hibernate.Query;

import java.util.List;

@Repository(entity = GoodsKeywordPO.class)
public class GoodsKeywordDaoImpl extends BaseRepositoryImpl<GoodsKeywordPO> implements GoodsKeywordDao {

    @Override
    public List<GoodsKeywordPO> hotKeywords() {
        Query query = createQuery("from GoodsKeywordPO order by amount desc");
        query.setMaxResults(10);
        return query.list();
    }

    @Override
    public GoodsKeywordPO findByKeyword(String keyword) {
        Query query = createQuery("from GoodsKeywordPO where keyword =:keyword");
        query.setString("keyword", keyword);
        query.setMaxResults(1);
        List list = query.list();
        if (list != null && !list.isEmpty()) {
            return (GoodsKeywordPO) list.get(0);
        }
        return null;
    }
}
